﻿Imports Microsoft.VisualBasic


Public Class clsCookie

    Public Shared Sub CookieSet(ByVal CookieName As String, ByVal CookieValue As String)
        Dim item As New HttpCookie(CookieName, HttpUtility.UrlDecode(CookieValue))
        Dim UserID As String = HttpContext.Current.Session("UserID")

        Response.Cookies(CookieName + "_" + UserID).Value = CookieValue
        Response.Cookies(CookieName + "_" + UserID).Expires = Now.AddMonths(1)

        HttpContext.Current.Response.Cookies.Add(item)
    End Sub

    Public Shared Function CookieGet(ByVal CookieName As String) As String
        Dim UserID As String = HttpContext.Current.Session("UserID")
        Dim Item As HttpCookie = HttpContext.Current.Request.Cookies(CookieName + "_" + UserID)

        If Item Is Nothing Then
            Return Nothing
        Else
            Return HttpUtility.UrlDecode(Item.Value)
        End If
    End Function

    Public Shared Sub CookieDelete(ByVal CookieName As String)
        If CookieGet(CookieName) IsNot Nothing Then
            Dim UserID As String = HttpContext.Current.Session("UserID")
            Dim item As New HttpCookie(CookieName + "_" + UserID)
            item.Expires = DateTime.Now.AddDays(-1)
            HttpContext.Current.Response.Cookies.Add(item)
        End If
    End Sub


End Class
